const http = require('http') 
const fs = require('fs');
const path = require('path');

var PORT = 2000

// 配置服务端口
    // 创建服务器
var server = http.createServer()
    // 服务器对请求做出响应
server.on("request", (req, res) => {    
    let url = req.url
    if (url === '/') url = '/index.html'
    console.log(path.join(__dirname, url))
    const fpath = path.join(__dirname, url)
    fs.readFile(fpath, 'utf8', (err, data) => {
        res.end(data)
    })
})
server.listen( PORT, (err) => {
    console.log(`Server runing at http://127.0.0.1:${PORT}/`); 
})
